<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->

@section('content')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>快递名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="express_name" lay-verify="required" lay-reqtext="必填项,请填写信息"
                               value="{{ $data['express_name'] }}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>订单满免
                    </label>
                    <div class="layui-input-inline">
                        <input type="number" name="order_money" lay-verify="required" lay-reqtext="必填项,请填写信息"
                               value="{{ $data['order_money'] }}" class="layui-input">
                    </div>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main" style=" width:500px; float:left;margin-left:90px;">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>地区名</th>
                            <th>首重(1KG)</th>
                            <th>续重(＞1KG)</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach( $data['area_list'] as $kk => $item)
                            <tr>
                                <td>{{ $item['area_id'] }}</td>
                                <td>{{ $item['area_name'] }}</td>
                                <td>
                                    <input type="number" name="areaList[{{$kk}}][first_unit]"
                                           value="{{$item['first_unit']}}"
                                           class="layui-input">
                                </td>
                                <td>
                                    <input type="number" name="areaList[{{$kk}}][two_unit]"
                                           value="{{$item['two_unit']}}"
                                           class="layui-input">
                                    <input type="hidden" name="areaList[{{$kk}}][area_id]" value="{{$item['area_id']}}">
                                    <input type="hidden" name="areaList[{{$kk}}][area_name]"
                                           value="{{$item['area_name']}}">
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <select name="status" lay-verify="required">
                                @foreach($statusList as $kk => $item)
                                    @if( $kk==$data['status'])
                                        <option value="{{ $kk }}" selected>{{ $item }}</option>
                                    @else
                                        <option value="{{ $kk }}">{{ $item }}</option>
                                    @endif
                                @endforeach
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" class="layui-textarea"
                                  name="remark">{{ $data['remark'] }}</textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <input type="hidden" value="{{ $data['id'] }}" name="id">
                    <button class="layui-btn" lay-filter="add" lay-submit="">提交</button>
                </div>
            </form>
        </div>
    </div>
    <script>
        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //监听提交
            form.on('submit(add)', function (data) {
                console.log(data);
                //发异步，把数据提交给php
                $.ajax({
                    type: 'POST',
                    url: '/admin/order/expressEdit',
                    data: data.field,
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        layer.alert(data.msg)
                        if (data.code == 1) {
                            //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        }
                    },
                    error: function (xhr, type) {
                        alert('Ajax error!')
                    }
                });

                return false;
            });

        });
    </script>

@endsection
